/*   1:    */ package org.intellij.plugins.relaxNG.compact.lexer;
/*   2:    */ 
/*   3:    */

import gnu.trove.TIntArrayList;
import gnu.trove.TIntIntHashMap;
import org.kohsuke.rngom.util.Utf16;

import java.io.FilterReader;
import java.io.IOException;
import java.io.Reader;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */ 
/*  10:    */ class EscapePreprocessor
/*  11:    */   extends FilterReader
/*  12:    */ {
/*  13:    */   private final TIntArrayList a;
/*  14:    */   private final TIntIntHashMap b;
/*  15:    */   private int c;
/*  16:    */   
/*  17:    */   public EscapePreprocessor(Reader paramReader, int paramInt, TIntIntHashMap paramTIntIntHashMap)
/*  18:    */   {
/*  19: 42 */     super(paramReader);
/*  20: 43 */     this.c = paramInt;
/*  21: 44 */     this.a = new TIntArrayList();
/*  22: 45 */     this.b = paramTIntIntHashMap;
/*  23:    */   }
/*  24:    */   
/*  25:    */   public int read(char[] paramArrayOfChar, int paramInt1, int paramInt2)
/*  26:    */     throws IOException
/*  27:    */   {
/*  28: 50 */     int i = read();
/*  29: 51 */     if (i == -1) {
/*  30: 52 */       return -1;
/*  31:    */     }
/*  32: 54 */     paramArrayOfChar[paramInt1] = ((char)i);
/*  33: 55 */     return 1;
/*  34:    */   }
/*  35:    */   
/*  36:    */   public int read()
/*  37:    */     throws IOException
/*  38:    */   {
/*  39: 60 */     if (this.a.size() > 0) {
/*  40: 61 */       return a();
/*  41:    */     }
/*  42: 63 */     int i = super.read();
/*  43: 64 */     if (i == -1) {
/*  44: 65 */       return -1;
/*  45:    */     }
/*  46: 67 */     this.c += 1;
/*  47: 69 */     switch (i)
/*  48:    */     {
/*  49:    */     case 13: 
/*  50: 71 */       if (!$assertionsDisabled) {
/*  51: 71 */         throw new AssertionError("Unexpected newline character");
/*  52:    */       }
/*  53: 72 */       if (b() == 10)
/*  54:    */       {
/*  55: 73 */         a();
/*  56: 74 */         this.b.put(this.c - 1, 2);
/*  57:    */       }
/*  58:    */     case 10: 
/*  59: 77 */       return 0;
/*  60:    */     case 92: 
/*  61: 80 */       int j = 0;
/*  62:    */       int k;
/*  63: 82 */       while ((k = b()) == 120) {
/*  64: 83 */         j++;
/*  65:    */       }
/*  66: 85 */       if ((j > 0) && (k == 123)) {
/*  67: 86 */         j++;
/*  68:    */       } else {
/*  69: 88 */         return i;
/*  70:    */       }
/*  71: 90 */       int m = 0;
/*  72: 91 */       while (a((char)(k = b())))
/*  73:    */       {
/*  74: 92 */         j++;
/*  75: 93 */         m <<= 4;
/*  76: 94 */         m |= Character.digit(k, 16);
/*  77:    */       }
/*  78: 96 */       if (k == 125) {
/*  79: 97 */         j++;
/*  80:    */       }
/*  81: 99 */       a(j);
/*  82:    */       
/*  83:101 */       this.b.put(this.c - 1, j);
/*  84:102 */       this.c += j;
/*  85:104 */       if (m <= 65535) {
/*  86:105 */         return m;
/*  87:    */       }
/*  88:108 */       this.a.add(Utf16.surrogate2(m));
/*  89:109 */       return Utf16.surrogate1(m);
/*  90:    */     }
/*  91:112 */     return i;
/*  92:    */   }
/*  93:    */   
/*  94:    */   private static boolean a(char paramChar)
/*  95:    */   {
/*  96:116 */     if (Character.isDigit(paramChar)) {
/*  97:116 */       return true;
/*  98:    */     }
/*  99:117 */     int i = Character.toLowerCase(paramChar);
/* 100:118 */     return (i >= 97) && (i <= 102);
/* 101:    */   }
/* 102:    */   
/* 103:    */   private int a()
/* 104:    */   {
/* 105:122 */     if (this.a.size() > 0)
/* 106:    */     {
/* 107:123 */       this.c += 1;
/* 108:124 */       return this.a.remove(0);
/* 109:    */     }
/* 110:126 */     return -1;
/* 111:    */   }
/* 112:    */   
/* 113:    */   private void a(int paramInt)
/* 114:    */   {
/* 115:130 */     this.a.remove(0, paramInt);
/* 116:    */   }
/* 117:    */   
/* 118:    */   private int b()
/* 119:    */     throws IOException
/* 120:    */   {
/* 121:134 */     int i = super.read();
/* 122:135 */     if (i == -1) {
/* 123:136 */       return -1;
/* 124:    */     }
/* 125:138 */     this.a.add(i);
/* 126:139 */     return i;
/* 127:    */   }
/* 128:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.compact.lexer.EscapePreprocessor

 * JD-Core Version:    0.7.0.1

 */